make sure we use the check profile where possible for lib deps.
authorNick Cameron <ncameron@mozilla.com>
Sat, 17 Dec 2016 19:08:14 +0000 (09:08 -1000)
committerNick Cameron <ncameron@mozilla.com>
Sun, 18 Dec 2016 21:17:38 +0000 (10:17 +1300)
Fixes #3418

src/cargo/ops/cargo_rustc/context.rs

index f01c0b141ed5b9d8dfea05550d38236133bf8909..1185fd64a8f23af5fa9200bfbeb50b2cdc58bf2b 100644 (file)
@@ -169,9 +169,9 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
                               kind: Kind)
                               -> CargoResult<()> {
         let rustflags = env_args(self.config,
-                                      &self.build_config,
-                                      kind,
-                                      "RUSTFLAGS")?;
+                                 &self.build_config,
+                                 kind,
+                                 "RUSTFLAGS")?;
         let mut process = self.config.rustc()?.process();
         process.arg("-")
                .arg("--crate-name").arg("___")
@@ -613,17 +613,10 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             match self.get_package(id) {
                 Ok(pkg) => {
                     pkg.targets().iter().find(|t| t.is_lib()).map(|t| {
-                        let profile = if unit.profile.check &&
-                                         !t.is_custom_build()
-                                         && !t.for_host() {
-                            &self.profiles.check
-                        } else {
-                            self.lib_profile()
-                        };
                         let unit = Unit {
                             pkg: pkg,
                             target: t,
-                            profile: profile,
+                            profile: self.lib_or_check_profile(unit, t),
                             kind: unit.kind.for_target(t),
                         };
                         Ok(unit)
@@ -780,7 +773,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             Unit {
                 pkg: unit.pkg,
                 target: t,
-                profile: self.lib_profile(),
+                profile: self.lib_or_check_profile(unit, t),
                 kind: unit.kind.for_target(t),
             }
         })
@@ -848,6 +841,14 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         }
     }
 
+    pub fn lib_or_check_profile(&self, unit: &Unit, target: &Target) -> &'a Profile {
+        if unit.profile.check && !target.is_custom_build() && !target.for_host() {
+            &self.profiles.check
+        } else {
+            self.lib_profile()
+        }
+    }
+
     pub fn build_script_profile(&self, _pkg: &PackageId) -> &'a Profile {
         // TODO: should build scripts always be built with the same library
         //       profile? How is this controlled at the CLI layer?